<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript prototype（原型对象）-prototype 继承-添加属性和方法-2</title>
</head>

<body>
    <!-- 当然我们也可以使用 prototype 属性就可以给对象的构造函数添加新的方法： -->

    <h2>JavaScript 对象</h2>

    <p id="demo"></p>

    <script>
        function Person(first, last, age, eye) {
            this.firstName = first;
            this.lastName = last;
            this.age = age;
            this.eyeColor = eye;
        }

        Person.prototype.name = function () {
            return this.firstName + " " + this.lastName
        };

        var myFather = new Person("John", "Doe", 50, "blue");
        document.getElementById("demo").innerHTML =
            "我的父亲是 " + myFather.name(); 
    </script>
</body>

</html>